package com.gismore.parser.excel.config;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gismore.parser.excel.common.util.PropertiesUtils;
import com.gismore.parser.excel.config.vo.TemplateSheet;
import org.aeonbits.owner.Config;
import org.aeonbits.owner.ConfigCache;
import org.aeonbits.owner.ConfigFactory;

import java.util.List;
import java.util.Properties;
import java.util.Set;

/**
 * Created by lei on 2017/6/23.
 */

public interface AppConfig extends Config{


	@DefaultValue("true")
	@Key("env")
	@ConverterClass(Converters.DevModeConverter.class)
	Boolean devMode();


	@Key("template.excel")
	@ConverterClass(Converters.ExcelTemplateConverter.class)
	@Separator(";")
	List<TemplateSheet> excelTemplate();



	static AppConfig me(){
		String configKey = "appConfig";

		if(ConfigCache.get(configKey) == null){
			String configFileName = "application.properties";

			Properties properties = PropertiesUtils.loadConfigProperties(configFileName);

			AppConfig appConfig = ConfigFactory.create(AppConfig.class, properties);
			ConfigCache.add(configKey,appConfig);
		}
		return ConfigCache.get(configKey);
	}

	static void init(){
		System.setProperty("log4j.configurationFile",PropertiesUtils.classPath("log4j2.xml"));

		String configFileName = "application.properties";
		Properties properties = PropertiesUtils.loadConfigProperties(configFileName);
		AppConfig appConfig = ConfigFactory.create(AppConfig.class, properties);
		ConfigCache.add("appConfig",appConfig);
	}
}
